package interview.huawei.tjt.training.dongtaiguihua;

import java.util.Scanner;

/**
 * 给两个整数数组 A 和 B ，返回两个数组中公共的、长度最长的子数组的长度。
 *
 * 示例：
 *
 * 输入： A: [1,2,3,2,1] B: [3,2,1,4,7] 输出：3 解释： 长度最长的公共子数组是 [3, 2, 1] 。
 *
 * 提示：
 *
 * 1 <= len(A), len(B) <= 1000
 * 0 <= A[i], B[i] < 100
 */
public class FindLength {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] strings1 = scanner.nextLine().split(",");
        String[] strings2 = scanner.nextLine().split(",");
        int[] A = new int[strings1.length];
        int[] B = new int[strings2.length];
        int[][] dp = new int[A.length + 1][B.length + 1];
        for (int i = 0; i < strings1.length; i ++) {
            if (!strings1[i].equals("")) {
                A[i] = Integer.parseInt(strings1[i]);
            }
            dp[i][0] = 0;
        }
        for (int i = 0; i < strings2.length; i ++) {
            if (!strings2[i].equals("")) {
                B[i] = Integer.parseInt(strings2[i]);
            }
            dp[0][i] = 0;
        }
        int len = 0;
        for (int i = 1; i <= A.length; i ++) {
            for (int j = 1; j <= B.length; j ++) {
                if (A[i - 1] == B[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    if (dp[i][j] > len) {
                        len = dp[i][j];
                    }
                }
            }
        }
        System.out.println(len);
    }

}
